package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/nsqio/go-nsq"
)

func main() {
	// f, err := os.Create("./myprofile.prof")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// pprof.StartCPUProfile(f)

	// go func() {
	// 	time.Sleep(time.Second * 30)
	// 	pprof.StopCPUProfile()
	// 	panic("shoudongpanic")
	// }()
	// t()
	// tnormal()
	tnormal()
}
func getPusher() *nsq.Producer {
	config := nsq.NewConfig()
	w, _ := nsq.NewProducer("127.0.0.1:4150", config)
	return w
}
func t() {
	w := getPusher()
	f, _ := os.Open("/Users/wangsiyuan/logs/uba-join/aa")
	scanner := bufio.NewScanner(f)

	for scanner.Scan() {
		err := w.Publish(`maction#ephemeral`, scanner.Bytes())
		if err != nil {
			log.Panic("Could not connect", err.Error())
		}
		time.Sleep(time.Microsecond * 500)
	}
	fmt.Println("------Done------")

}

func tnormal() {
	var pubidsmsg = []string{`"pubID":"aaaabcabcabcabcabc11",name=wsy`, `"pubID":"bbbabcabcabcabcabc11",age=24`, `"pubID":"cccabcabcabcabcabc11",job=farmer`}
	w := getPusher()
	for i := 0; i < 1111; i++ {
		time.Sleep(time.Second * 1)
		fmt.Println(i)
		w.Publish(`maction#ephemeral`, []byte(pubidsmsg[i%3]))
	}
}
